package {{ base_pkg }}.adapter.inbound.rest.{{ entity.domain }};

import {{ base_pkg }}.application.{{ entity.domain }}.dto.{{ entity.name }}DTO;
import {{ base_pkg }}.application.{{ entity.domain }}.{{ entity.name }}UseCase;
import {{ base_pkg }}.adapter.inbound.rest.{{ entity.domain }}.vo.{{ entity.name }}VO;
import {{ base_pkg }}.adapter.inbound.rest.{{ entity.domain }}.request.{{ entity.name }}Req;
import {{ base_pkg }}.adapter.inbound.rest.{{ entity.domain }}.converter.{{ entity.name }}ReqConverter;
import {{ base_pkg }}.adapter.inbound.rest.{{ entity.domain }}.converter.{{ entity.name }}VOConverter;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/{{ entity.name }}")
public class {{ entity.name }}Controller {
    private final {{ entity.name }}UseCase {{ entity.name }}UseCase;
    private final {{ entity.name }}ReqConverter {{ entity.name|lower }}ReqConverter;
    private final {{ entity.name }}VOConverter {{ entity.name|lower }}VOConverter;

    @Autowired
    public {{ entity.name }}Controller({{ entity.name }}UseCase {{ entity.name }}UseCase,
                                      {{ entity.name }}ReqConverter {{ entity.name|lower }}ReqConverter,
                                      {{ entity.name }}VOConverter {{ entity.name|lower }}VOConverter) {
        this.{{ entity.name }}UseCase = {{ entity.name }}UseCase;
        this.{{ entity.name|lower }}ReqConverter = {{ entity.name|lower }}ReqConverter;
        this.{{ entity.name|lower }}VOConverter = {{ entity.name|lower }}VOConverter;
    }

    @PostMapping("/create")
    public {{ entity.name }}VO create(@RequestBody {{ entity.name }}Req req) {
        {{ entity.name }}DTO dto = {{ entity.name|lower }}ReqConverter.toDTO(req);
        {{ entity.name }}DTO created = {{ entity.name }}UseCase.create(dto);
        return {{ entity.name|lower }}VOConverter.fromDTO(created);
    }

    @GetMapping("/list")
    public List<{{ entity.name }}VO> list() {
        List<{{ entity.name }}DTO> dtoList = {{ entity.name }}UseCase.list();
        return dtoList.stream().map({{ entity.name|lower }}VOConverter::fromDTO).collect(Collectors.toList());
    }
} 